//
//  TLST_DetailCell.m
//  Travel_World
//
//  Created by lanou on 15/10/13.
//  Copyright © 2015年 TLS. All rights reserved.
//

#import "TLST_DetailCell.h"
#import "TLST_DetailModel.h"
#import "TLST_DetailFrameModel.h"
#import "UIImageView+WebCache.h"

@implementation TLST_DetailCell
+ (instancetype)tcellWithTableView:(UITableView *)tableView{
    static NSString *ID = @"detailCell";
    TLST_DetailCell *cell = [tableView dequeueReusableCellWithIdentifier:ID];
    if (cell == nil) {
        cell = [[TLST_DetailCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:ID];
    }
    return cell;
}
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.avatarView = [[UIImageView alloc] init];
        [self.contentView addSubview:self.avatarView];
        self.avatarView.layer.cornerRadius = 25*WID;
        self.avatarView.layer.masksToBounds = YES;
        
        self.titleLabel = [[UILabel alloc] init];
        self.titleLabel.font = [UIFont systemFontOfSize:15];
        self.titleLabel.numberOfLines = 0;
        [self.contentView addSubview:self.titleLabel];
        
        self.ULLabel = [[UILabel alloc] init];
        self.ULLabel.textAlignment = NSTextAlignmentLeft;
        self.ULLabel.textColor = [UIColor grayColor];
        self.ULLabel.font = [UIFont systemFontOfSize:12];
        [self.contentView addSubview:self.ULLabel];
        
        self.VRLabel = [[UILabel alloc] init];
        self.VRLabel.textAlignment = NSTextAlignmentRight;
        self.VRLabel.textColor = [UIColor grayColor];
        self.VRLabel.font = [UIFont systemFontOfSize:12];
        [self.contentView addSubview:self.VRLabel];
    }
    return self;
}
- (void)layoutSubviews
{
    [super layoutSubviews];
    self.avatarView.frame = self.detailFrameModel.avatarF;
    self.titleLabel.frame = self.detailFrameModel.titleF;
    self.ULLabel.frame = self.detailFrameModel.userLastF;
    self.VRLabel.frame = self.detailFrameModel.vreplysF;
}
- (void)setDetailFrameModel:(TLST_DetailFrameModel *)detailFrameModel
{
    if (_detailFrameModel != detailFrameModel) {
        _detailFrameModel = detailFrameModel;
    }
    TLST_DetailModel *detailModel = detailFrameModel.detailModel;
    [self.avatarView sd_setImageWithURL:[NSURL URLWithString:detailModel.avatar] placeholderImage:[UIImage imageNamed:@"WplaceImage.jpg"]];
    self.titleLabel.text = detailModel.title;
    
    NSDate *date = [NSDate dateWithTimeIntervalSince1970:detailModel.lastpost];
    NSDateFormatter *formatter = [[NSDateFormatter alloc]init];
    [formatter setDateFormat:@"MM-dd HH:mm"];
    NSString *dateStr = [formatter stringFromDate:date];
    self.ULLabel.text = [NSString stringWithFormat:@"%@ | %@",detailModel.username,dateStr];
    
    self.VRLabel.text = [NSString stringWithFormat:@"👀%@  💓%@",detailModel.views,detailModel.replys];
}
- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
